home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 126-150 / scopedisk132 / redate / redate.asm < prev    next >
Assembly Source File  |  1995-03-19  |  14KB  |  448 lines

  1. ;   ReDate 1.1/ SetDate DIRs according to contents
  2. ;        - Jim Butterfield.  April 7/90.
  3. ; Exec library calls
  4. _LVOAllocMem          EQU -$C6
  5. _LVOFreeMem           EQU -$D2
  6. _LVOFindTask          EQU -$126
  7. _LVOSetSignal         EQU -$132
  8. _LVOAllocSignal       EQU -$14A
  9. _LVOFreeSignal        EQU -$150
  10. _LVOPutMsg            EQU -$16E
  11. _LVOGetMsg            EQU -$174
  12. _LVOWaitPort          EQU -$180
  13. _LVOCloseLibrary      EQU -$19E
  14. _LVOOpenLibrary       EQU -$228
  15. ; DOS library calls
  16. _LVOOpen              EQU -$1E
  17. _LVOClose             EQU -$24
  18. _LVORead              EQU -$2A
  19. _LVOWrite             EQU -$30
  20. _LVOOutput            EQU -$3C
  21. _LVOLock              EQU -$54
  22. _LVOUnLock            EQU -$5A
  23. _LVOExamine           EQU -$66
  24. _LVOExNext            EQU -$6C
  25. _LVOCurrentDir        EQU -$7E
  26. _LVOIoErr             EQU -$84
  27. _LVODeviceProc        EQU -$AE
  28. ;
  29. ACCESS_READ            equ -2
  30. MODE_OLDFILE           equ 1005
  31. INFOSIZE               equ 260
  32. ; sizeof (struct MsgPort+struct Message+struct DosPacket+108+4)
  33. DATASIZE               equ $24+$14+$30+112
  34. ; FileInfoBlock items
  35. fib_FileName           equ 8
  36. fib_EntryType          equ 120
  37. fib_Date               equ 132
  38. ; IO Error Type
  39. NO_MORE_ENTRIES        equ 232
  40. ;
  41. ;-- Initial setup:
  42. ;        offsets from A5 (Globals)
  43. FileErr   equ -4
  44. ; Level not needed this version, but might be useful for expansion
  45. Level     equ -8
  46. DevProc   equ -12
  47. dosBase   equ -16
  48. argv      equ -20
  49. OutHandle equ -24
  50. DataBlk   equ -28    ;Mport/Msg/dos packet/Name block
  51. message   equ -32
  52. DosPkt    equ -36
  53. Nope      equ -37    ;byte .. update didn't work
  54. Yup       equ -38    ;byte .. update worked
  55. Mebbe     equ -39    ;byte .. update tried
  56. Abort     equ -40    ;byte
  57.  
  58. go     link   a5,#-40         ; common work area
  59.        moveq  #0,d1
  60.        move.l d1,Abort(a5)    ; four bytes
  61.        move.b d1,-1(a0,d0)    ; c style string
  62. spdump move.b (a0)+,d0        ; skip init spaces
  63.        cmp.b  #$20,d0
  64.        beq.s  spdump
  65.        move.b -(a0),d7        ; grab first char
  66.        move.l a0,argv(a5)
  67. ;**  Level=0;
  68.        move.l d1,Level(a5)
  69. ; set up dos, DevProc, output, here
  70.        moveq  #1,d0
  71.        move.l d0,FileErr(a5)
  72.        moveq  #20,d6            ; return FAIL
  73.        lea    dosname(pc),a1    ; Name 'dos.library'.
  74.        moveq  #33,d0            ;   1.2 or later
  75.        move.l $4,a6             ;   Using Exec library
  76.        jsr    _LVOOpenLibrary(a6)  ;   Open Dos library.
  77.        move.l d0,dosBase(a5)    ; Remember DosBase ptr.
  78.        beq    StartupQuit       ;      dos not opened
  79.        move.l d0,a6             ; set Dos library
  80.        jsr    _LVOOutput(a6)    ;   get CLI outhandle,
  81.        move.l d0,OutHandle(a5)       ;   & then remember it.
  82.        tst.b  d7                ; no file name?
  83.        beq    Prompt
  84.        move.l argv(a5),d1       ; file name
  85.        jsr    _LVODeviceProc(A6)
  86.        move.l d0,DevProc(a5)    ; device handler
  87.        beq    DosQuit
  88. ; MakePort(Az=0,D7=0)
  89.        move.l 4,a6              ; exec library 
  90.        move.l #DATASIZE,d0
  91.        move.l  #$10001,d1       ;public|clear
  92.        jsr     _LVOAllocMem(a6)
  93.        move.l  d0,a3
  94.        move.l  a3,DataBlk(a5)
  95.        beq     DosQuit
  96.        lea     $24(a3),a0   ;keep longword alignment!
  97.        move.l  a0,message(a5)
  98.        lea     $14(a0),a0
  99.        move.l  a0,DosPkt(a5)
  100. ; make the port .. alloc signal
  101.        moveq   #-1,d0
  102.        jsr     _LVOAllocSignal(a6)
  103.        cmp.b   #$FF,d0
  104.        beq.s   _NoSignal      ;couldn't get signal
  105.        move.b  d0,15(a3)      ;mp_SigBit
  106.        move.b  #4,8(a3)       ;mp_Node.ln_Type=NT_MSGPORT
  107.        clr.b   14(a3)         ;mp_Flags=PA_SIGNAL
  108.        sub.l   a1,a1
  109.        jsr     _LVOFindTask(a6)
  110.        move.l  d0,$10(a3)     ;*mp_SigTask
  111. ; construct empty MsgList
  112.        lea     $18(a3),a0     ;mp_MsgList.lh_Tail (contns 0)
  113.        move.l  a0,$14(a3)     ; to mp_MsgList.lh_Head
  114.        lea     $14(a3),A0     ;mp_MsgList.lh_Head
  115.        move.l  a0,$1C(a3)     ; to mp_MsgList.lhTailPred
  116.        clr.l   $18(a3)        ;mp_MsgList.lh_Tail
  117.        move.b  #2,$20(a3)     ;mp_MsgList.lh_type
  118. ;**    GetToWork(argv[1]);
  119.        move.l argv(a5),a0
  120.        bsr    GetToWork
  121.  
  122. ; Wind up port here; Scrap(A3=address)
  123.         move.l  DataBlk(a5),a3
  124.     MOVE.B    #$FF,8(A3)
  125.     MOVEQ    #-1,D0
  126.     MOVE.L    D0,$14(A3)
  127.     MOVEQ    #0,D0
  128.     MOVE.B    15(A3),D0
  129.     MOVE.L    4,A6
  130.     JSR    _LVOFreeSignal(A6)
  131. ; Can't get the signal
  132. _NoSignal    MOVE.L    A3,A1
  133.     MOVE.L    #DATASIZE,D0       
  134.     JSR    _LVOFreeMem(A6)
  135. ; Can't get the allocate
  136. DosQuit  move.l dosBase(a5),a6    ; set Dos Library
  137.  
  138. ;**    switch (FileErr)
  139.        move.l argv(a5),a0
  140.        move.l FileErr(a5),d0
  141. ;**      {
  142. ;**      case 0:
  143.        bne.s  Ncase0
  144.        tst.b  Yup(a5)
  145.        beq.s  NotYup
  146.        moveq  #0,d6            ; return OK
  147.        move.l OutHandle(a5),d1 ; file handle
  148.        lea    SDupMsg(pc),a1
  149.        move.l a1,d2            ; outbuffer
  150.        moveq  #SDupLen,d3      ; length
  151.        jsr    _LVOWrite(A6)
  152.  
  153. NotYup tst.b  Nope(a5)
  154.        beq.s  NotNo
  155.        moveq  #5,d6             ; return WARN
  156.        move.l OutHandle(a5),d1  ; file handle
  157.        lea    SDnupMsg(pc),a1
  158.        move.l a1,d2             ; outbuffer
  159.        moveq  #SDnupLen,d3      ; length
  160.        jsr    _LVOWrite(A6)
  161.  
  162. NotNo  tst.b  Mebbe(a5)
  163.        bne.s  endSwitch
  164.        moveq  #10,d6            ; return ERROR
  165.        move.l OutHandle(a5),d1  ; file handle
  166.        lea    SDnfMsg(pc),a1 
  167.        move.l a1,d2             ; outbuffer
  168.        moveq  #SDnfLen,d3       ; length
  169.        jsr    _LVOWrite(A6)
  170. ;**        break;
  171.        bra.s  endSwitch
  172. ;**      case 1:
  173. ;**        printf("Out of Memory\n");
  174. Ncase0 cmp.l  #1,d0
  175.        bne.s  Ncase1
  176.        move.l OutHandle(a5),d1  ;file handle
  177.        lea    NoMemMsg(pc),a1
  178.        move.l a1,d2             ;outbuffer
  179.        moveq  #NoMemLen,d3      ;length
  180.        jsr    _LVOWrite(A6)
  181. ;**        break;
  182.        bra.s  endSwitch
  183. ;**      case 2:
  184. ;**        printf("Can't find directory.\n");
  185. Ncase1      cmp.l  #2,d0
  186.        bne.s  endSwitch
  187.        move.l OutHandle(a5),d1  ;file handle
  188.        lea    NoFileMsg(pc),a1
  189.        move.l a1,d2             ;outbuffer
  190.        moveq  #NoFileLen,d3     ;length
  191.        jsr    _LVOWrite(A6)
  192. endSwitch   bra.s  LastGasp
  193. ;**      }
  194. ;**    }
  195. ;**  else printf("FORMAT:  ReDate <DirectoryName>\n");
  196. Prompt      move.l OutHandle(a5),d1
  197.        lea    PromptMsg(pc),a1
  198.        move.l a1,d2
  199.        moveq  #PromptLen,d3
  200.        jsr    _LVOWrite(A6)
  201.        moveq  #0,d6             ; return OK
  202. ;**  }
  203. LastGasp: move.l dosBase(a5),a1 ; DosBase to a1;
  204.        move.l $4,a6             ; using Exec library,
  205.        jsr    _LVOCloseLibrary(a6)   ;   close Dos library.
  206. StartupQuit unlk   a5
  207.        move.l d6,d0                  ; return code
  208.        rts                           ; End of Program
  209.  
  210. ;** *struct DateStamp GetToWork(char * Name)
  211. ;**  {
  212. ;**  unsigned long newLock, oldLock;
  213. ;**  struct FileInfoBlock *fibb;
  214. ;**  char *NameSave;
  215. ;            offsets from A4
  216. Days        equ    -4
  217. Minutes     equ    -8
  218. Ticks       equ    -12
  219. newLock     equ    -16
  220. oldLock     equ    -20
  221. fibb        equ    -24
  222. NameSave    equ    -28
  223.  
  224. GetToWork     link   A4,#-28
  225.        move.l a0,NameSave(a4)
  226. ;**  Date[]=0;
  227.        moveq  #90,d0         ;for April 1 1978
  228.        move.l d0,Days(a4)
  229.        move.l d0,Minutes(a4)
  230.        move.l d0,Ticks(a4)
  231. ;**  FileErr =1;   /* Alloc error */
  232.        moveq  #1,d0
  233.        move.l d0,FileErr(a5)
  234. ;**  if ((fibb = AllocMem(INFOSIZE,0)) != 0)
  235.        move.l $4,a6             ; this calls for Exec
  236.        moveq  #0,d1             ; any type of memory
  237.        move.l #INFOSIZE,d0      ; size of block needed
  238.        jsr    _LVOAllocMem(a6)  ; go get it
  239.        move.l dosBase(a5),a6    ; restore Dos Library
  240.        move.l d0,fibb(a4)       ; save the block address
  241.        beq    GDExit            ; quit if no memory
  242. ;**    {
  243. ;**      FileErr =2;   /* file unreadable */
  244.        moveq  #2,d0
  245.        move.l d0,FileErr(a5)
  246. ;**      if ((newLock = Lock(Name,ACCESS_READ)) != 0)
  247.        move.l NameSave(a4),d1
  248.        moveq  #ACCESS_READ,D2   ; get a read lock
  249.        jsr    _LVOLock(a6)
  250.        move.l d0,newLock(a4)    ; store the lock pointer
  251.        beq    DropMem           ; couldn't get lock
  252. ;**      { if ((Examine(newLock,fibb)) != 0)
  253.        move.l d0,d1             ; lock
  254.        move.l fibb(a4),d2       ; file info block address
  255.        jsr _LVOExamine(a6)      ; go for the data
  256. ;   Assume Examine never fails.  Go for the data.
  257. ;**        {
  258. ;**        FileErr =0;    /* got file, normal error sequence */
  259.        moveq  #0,d0
  260.        move.l d0,FileErr(a5)
  261. ;**        if (fibb->fib_EntryType < 0)
  262.        move.l fibb(a4),a3       ; file info block address
  263.        move.l fib_EntryType(a3),d0
  264.        bpl.s  DirLoop
  265. ;**          {
  266. ;**          printf(" Not a Directory!/n");
  267.        move.l OutHandle(a5),d1
  268.        lea    NotDirMsg(pc),a1
  269.        move.l a1,d2
  270.        moveq  #NotDirLen,d3
  271.        jsr    _LVOWrite(A6)
  272.        bra    DropLock
  273. ;**        else
  274. DirLoop:
  275. ;**    {
  276. ;**            if ((ExNext(newLock,fibb)) == 0)
  277.        move.l newLock(a4),d1   ; lock
  278.        move.l fibb(a4),d2      ; file info block address
  279.        jsr    _LVOExNext(a6)      ; go for the data
  280.        tst.l  d0
  281.        beq    DropLock
  282. ;**         {
  283. ;**              if (fibb->fib_EntryType < 0)
  284.        tst.l  fib_EntryType(a3)
  285.        bmi    TypeFile
  286. ;**  We found a directory .. we got work.
  287. ;**           {
  288. ;**                oldLock = CurrentDir(newLock);
  289.        move.l newLock(a4),d1
  290.        jsr    _LVOCurrentDir(a6)
  291.        move.l d0,oldLock(a4)
  292. ;**                Level += 1;
  293.        addq   #1,Level(a5)
  294. ;**                GetDir(fibb->fib_FileName);
  295.        lea    fib_FileName(a3),a0
  296.        bsr    GetToWork
  297.        move.l fibb(a4),a3       ; file info block address
  298.        move.l d0,fib_Date(a3)
  299.        move.l d1,fib_Date+4(a3)
  300.        move.l d2,fib_Date+8(a3)
  301. ;**            Level -= 1;
  302.        subq   #1,Level(a5)
  303. ;**                newLock = CurrentDir(oldLock);
  304.        move.l oldLock(a4),d1
  305.        jsr    _LVOCurrentDir(a6)
  306.        move.l d0,newLock(a4)
  307. ;**         This is where we build the packet.  Ouch.
  308. ; sendpkt(a3=struct MsgPort *pid,a2=LONG args)
  309.         move.l  DosPkt(a5),a0
  310.         lea     $30(a0),a0         ;BSTR site
  311.         lea     fib_FileName(a3),a1  ;name
  312.         moveq   #0,d0
  313. NmLp    move.b  0(a1,d0.w),1(a0,d0.w)
  314.         beq.s   NmEnd
  315.         addq.w  #1,d0
  316.         cmp.w   #108,d0
  317.         bne.s   NmLp
  318. NmEnd   move.b  d0,(a0)    ;len
  319.         move.l  a0,d7
  320.         lsr.l   #2,d7      ;BSTR address
  321. ; message.mn_Node.ln_Name = &(dosPacket);
  322.     MOVE.L    DosPkt(A5),A0
  323.     MOVE.L    message(A5),A1
  324.     MOVE.L    A0,10(A1)
  325. ; dosPacket.dp_Link = &(message);
  326.     MOVE.L    A1,0(A0)
  327. ; dosPacket.dp_Port = replyport;
  328.     MOVE.L    DataBlk(A5),$18(A1)
  329. ; dosPacket.dp_Type = action;
  330.     MOVE.L    #34,$1C(A1)
  331. ; dosPacket.dp_Arg1 = 0;
  332.     LEA    $28(A1),A0    ;arg1
  333. ; arg1=NULL    MOVE.L    #0,0(A0)
  334. ; dosPacket.dp_Arg2 = parentlock;
  335.        move.l newLock(a4),4(a0)   ; lock
  336. ; dosPacket.dp_Arg3 = BSTR(filename);
  337.        move.l d7,8(A0)     ; BSTR
  338. ; dosPacket.dp_Arg4 = &datestamp;
  339.        lea    fib_Date(a3),a1
  340.        move.l a1,12(A0)    ; Ptr to datestamp
  341. ; PutMsg(pid,message);
  342.        move.l DevProc(A5),A0
  343.     MOVE.L    message(A5),A1
  344.     MOVE.L    4,A6
  345.     JSR    _LVOPutMsg(A6)
  346. ; WaitPort(replyport); GetMsg(replyport);
  347.     MOVE.L    DataBlk(A5),A0
  348.     JSR    _LVOWaitPort(A6)
  349.     MOVE.L    DataBlk(A5),A0
  350.     JSR    _LVOGetMsg(A6)
  351. ; res1 = dosPacket.dp_Res1;
  352.        moveq   #1,d1
  353.        lea     Nope(a5),a1
  354.        move.l  message(A5),A0
  355.        move.l  $20(A0),D0
  356. ; $FFFFF is success
  357.        beq.s  NGood
  358.        lea    Yup(a5),a1
  359. NGood  move.b d1,(a1)
  360.        move.b d1,Mebbe(a5)
  361. ;**                }  /* dir */
  362. TypeFile:
  363. ; if FileName <> #?.info
  364.        lea    fib_FileName(a3),a0
  365. TryChx move.b (a0)+,d0
  366.        bne.s  TryChx
  367.        lea    -6(a0),a0
  368.        lea    InfoLine(pc),a1
  369. InfLp  cmp.b  (a0)+,(a1)+
  370.        beq.s  InfLp
  371.        tst.b  -1(a0)
  372.        beq.s  Rejoin2        
  373. ;**                {
  374.        move.l fib_Date(a3),d0
  375.        move.l fib_Date+4(a3),d1
  376.        move.l fib_Date+8(a3),d2
  377.        cmp.l  Days(a4),d0
  378.        bne.s  ckDate
  379.        cmp.l  Minutes(a4),d1
  380.        bne.s  ckDate
  381.        cmp.l  Ticks(a4),d2
  382. ckDate bcs.s  Rejoin2
  383.        move.l d0,Days(a4)
  384.        move.l d1,Minutes(a4)
  385.        move.l d2,Ticks(a4)
  386. ;**                }  /* file */
  387. Rejoin2:
  388.        tst.b  Abort(a5)
  389.        bne.s  DropLock
  390.        moveq  #0,d0
  391.        move.l #$1000,d1
  392.        move.l $4,a6
  393.        jsr    _LVOSetSignal(a6)
  394.        move.l dosBase(a5),a6    ; restore Dos Library
  395.        and.l  #$1000,d0
  396.        beq.s  NotCtrlC
  397.        move.b #1,Abort(a5)
  398. NotCtrlC:   tst.b Abort(a5)
  399.        beq   DirLoop
  400. ; print Ctrl-C signal       
  401.        move.l OutHandle(a5),d1
  402.        lea    CtrlCMsg(pc),a1
  403.        move.l a1,d2
  404.        moveq  #CtrlCLen,d3
  405.        jsr    _LVOWrite(A6)
  406. ;**        } /* primary dir not file */
  407. ;**       }   /* Examine OK */
  408. ;**      UnLock(newLock);
  409. DropLock    move.l dosBase(a5),a6    ; set Dos Library
  410.        move.l newLock(a4),d1    ; take off the lock
  411.        jsr    _LVOUnLock(a6)
  412. ;**      }      /* Lock OK */
  413. ;**    FreeMem(fibb,INFOSIZE);
  414. DropMem:    move.l $4,a6             ; set Exec library
  415.        move.l fibb(a4),a1       ; memory block address
  416.        move.l #INFOSIZE,d0      ; size of block
  417.        jsr    _LVOFreeMem(a6)   ; release this memory
  418.        move.l dosBase(a5),a6    ; set Dos Library
  419. ;**    }        /* Alloc OK */
  420.        move.l Days(a4),d0
  421.        move.l Minutes(a4),d1
  422.        move.l Ticks(a4),d2
  423. GDExit:     unlk   A4
  424.        rts
  425. ;**  }
  426.  
  427. NotDirMsg   dc.b   'Not a directory!',$a
  428. NotDirLen   equ    *-NotDirMsg
  429. PromptMsg   dc.b   'ReDate (by Jim Butterfield) V1.0',$0a
  430.             dc.b   'FORMAT:  ReDate <directory>',$0a
  431. PromptLen   equ    *-PromptMsg
  432. SDupMsg     dc.b   'Subdirectories updated.',$a
  433. SDupLen     equ    *-SDupMsg
  434. SDnupMsg    dc.b   'Subdirectories not updated.',$a
  435. SDnupLen    equ    *-SDnupMsg
  436. SDnfMsg     dc.b   'No subdirectories seen.',$a
  437. SDnfLen     equ    *-SDnfMsg
  438. NoMemMsg    dc.b   'Out of Memory',$0a
  439. NoMemLen    equ    *-NoMemMsg
  440. NoFileMsg   dc.b   'Can t find file.',$0a
  441. NoFileLen   equ    *-NoFileMsg
  442. CtrlCMsg    dc.b   '^C',$0a
  443. CtrlCLen    equ    *-CtrlCMsg
  444. InfoLine    dc.b   '.info'
  445. dosname     dc.b   'dos.library',0
  446.             end
  447.  
  448.